/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function Function() {
    this.javaClass = "org.workforce.core.FunctionSystem";
    this.id = "";
    this.name = "";
    this.description = "";
    this.createDate = "";
    this.lastUpdate = "";
    this.expireDate = "";
    this.effectiveDate = "";
    this.isActive = "";
}
function mainFunction() {
    var body = document.getElementById("_body");
    body.innerHTML = requestPage("FunctionSystem.main.jsp");
    body.style.visibility = "visible";
}
function addFunction() {
    var oFunction = new Function();
    oFunction.id = "";
    oFunction.name = document.getElementById("function_pre_name").value;
    oFunction.description = document.getElementById("function_pre_description").value;
    var date = new Date();
    oFunction.createDate = ""+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+"";
    oFunction.lastUpdate = ""+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+"";
    oFunction.expireDate = document.getElementById("function_pre_expriseDate").value;
    oFunction.effectiveDate = document.getElementById("function_pre_effectiveDate").value;
    oFunction.isActive = document.getElementById("function_pre_isActive").value;
    var chk = serviceLocator.saveFunction(oFunction);
    if( chk == "true" ) {
        alert("Add Function Complete.");
    } else {
        alert("Cann't Add Function.");
    }
}
function clearFunction() {
    document.getElementById("function_pre_name").value = "";
    document.getElementById("function_pre_description").value = "";
    document.getElementById("function_pre_expriseDate").value = "";
    document.getElementById("function_pre_effectiveDate").value = "";
}
function saveFunction() {
    loading();
    var obj = new Function();
    obj.id = document.getElementById("function_pre_id").value;
    obj.name = document.getElementById("function_pre_name").value;
    obj.description = document.getElementById("function_pre_description").value;
    obj.isActive = document.getElementById("function_pre_isActive").value;
    obj.effectiveDate = document.getElementById("function_pre_effectiveDate").value;
    obj.expireDate = document.getElementById("function_pre_expriseDate").value;
    var date = new Date();
    obj.lastUpdate = ""+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+"";
    obj.createDate = ""+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+"";
    var chk = serviceLocator.updateFunction(obj);
    if( chk == "true" ) {
        alert("Update Function Complete.");
    } else {
        alert("Cann't Update Function!");
    }
    unloading();
}
function searchFunction() {
    loading();
    var oFunction = new Function();
    oFunction.name = document.getElementById("functionName").value;
    var pages = serviceLocator.pageSearchCritiriaFunction(oFunction);
    var ls = serviceLocator.searchCritiriaFunction(oFunction, 0);
    setTableHeader("functionTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description", "Last Update"], pages.count, ""+pages.iterator, "searchFunctionN");
    loadTable("id,name,description,lastUpdate", ls, "functionTable","delFunction","edtFunction");
    unloading();
}
function searchFunctionN(offset) {
    loading();
    var oFunction = new Function();
     oFunction.name = document.getElementById("functionName").value;
    var pages = serviceLocator.pageSearchCritiriaFunction(oFunction);
    var ls = serviceLocator.searchCritiriaFunction(oFunction, offset);
    setTableHeader("functionTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description", "Last Update"], pages.count, ""+pages.iterator, "searchFunctionN");
    loadTable("id,name,description,lastUpdate", ls, "functionTable","delFunction","edtFunction");
    unloading();
}
function delFunction(id) {
    var sysConfirm = new SysConfirm();
    sysConfirm.message = "You do want delete id["+id+"]";
    sysConfirm.callOK = "function_confirm_delete_ok('"+id+"')";
    sysConfirm.confirm();
}
function function_confirm_delete_ok(id) {
    var oFunction = new Function();
    oFunction.id = id;
    serviceLocator.removeFunction(oFunction);
    searchFunction();
}
function edtFunction(id) {
    loading();
    var oFunction = new Function();
    oFunction.id = id;
    var functionEdit = serviceLocator.findFunction(oFunction);
    actionForward('_body','FunctionSystem.form.jsp');
    document.getElementById("function_pre_id").value = functionEdit.id;
    document.getElementById("function_pre_name").value = functionEdit.name;
    document.getElementById("function_pre_description").value = functionEdit.description;
    document.getElementById("function_pre_effectiveDate").value = functionEdit.effectiveDate;
    document.getElementById("function_pre_expriseDate").value = functionEdit.expireDate;
    document.getElementById("function_pre_isActive").value = functionEdit.isActive;
    document.getElementById("function_pre_save").setAttribute("onclick", "saveFunction()");
    unloading();
}

